put the API version as #defines in the header file (as discussed in #30)
authorSteven G. Johnson <stevenj@mit.edu>
Fri, 27 Mar 2015 16:35:41 +0000 (12:35 -0400)
committerSteven G. Johnson <stevenj@mit.edu>
Fri, 27 Mar 2015 16:35:41 +0000 (12:35 -0400)
NEWS.md
test/printproperty.c
utf8proc.c
utf8proc.h

diff --git a/NEWS.md b/NEWS.md
index a45e9ac83bef2959acaa2c6bd839b381610e8d25..37f3a8992749357bb08a66e4d19cc193855d04ec 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
 
 - Most `#defined` constants are now `enums`.
 
+- New preprocessor constants `UTF8PROC_VERSION_MAJOR`,
+  `UTF8PROC_VERSION_MINOR`, and `UTF8PROC_VERSION_PATCH` for compile-time
+  detection of the API version.
+
 - Doxygen-formatted documentation.
 
 ## Version 1.1.6 ##
index 6be8cb13e7db4f5790512d74538b166aa59fcff2..b876f0cfe711300b6614c6f20b3c629f63b7c56d 100644 (file)
@@ -8,6 +8,10 @@ int main(int argc, char **argv)
 
      for (i = 1; i < argc; ++i) {
           int c;
+          if (!strcmp(argv[i], "-V")) {
+               printf("utf8proc version %s\n", utf8proc_version());
+               continue;
+          }
           check(sscanf(argv[i],"%x",&c) == 1, "invalid hex input %s", argv[i]);
           const utf8proc_property_t *p = utf8proc_get_property(c);
           printf("U+%s:\n"
index b0c68e7305776bbbfeeb41d30fdc809093015315..c66b1aeb3bf5fc5d0115643f1725ce895a68e1ff 100644 (file)
@@ -84,8 +84,10 @@ DLLEXPORT const int8_t utf8proc_utf8class[256] = {
 /* Should follow semantic-versioning rules (semver.org) based on API
    compatibility.  (Note that the shared-library version number will
    be different, being based on ABI compatibility.): */
+#define STRINGIZEx(x) #x
+#define STRINGIZE(x) STRINGIZEx(x)
 DLLEXPORT const char *utf8proc_version(void) {
-  return "1.2-dev";
+     return STRINGIZE(UTF8PROC_VERSION_MAJOR) "." STRINGIZE(UTF8PROC_VERSION_MINOR) "." STRINGIZE(UTF8PROC_VERSION_PATCH) "-dev";
 }
 
 DLLEXPORT const char *utf8proc_errmsg(ssize_t errcode) {
index dc97b85b4e10e0579376dfdab3294c6d5e58f19c..d1085fc316a52b7cf7021e1a14080fbddff74bf0 100644 (file)
 #ifndef UTF8PROC_H
 #define UTF8PROC_H
 
+/** @name API version
+ *  
+ * The utf8proc API version MAJOR.MINOR.PATCH, following
+ * semantic-versioning rules (http://semver.org) based on API
+ * compatibility.
+ *
+ * This is also returned at runtime by @ref utf8proc_version; however, the
+ * runtime version may append a string like "-dev" to the version number
+ * for prerelease versions.
+ *
+ * @note The shared-library version number in the Makefile will be different,
+ *       being based on ABI compatibility rather than API compatibility.
+ */
+/** @{ */
+/** The MAJOR version number (increased when backwards API compatibility is broken). */
+#define UTF8PROC_VERSION_MAJOR 1
+/** The MINOR version number (increased when new functionality is added in a backwards-compatible manner). */
+#define UTF8PROC_VERSION_MINOR 2
+/** The PATCH version (increased for fixes that do not change the API). */
+#define UTF8PROC_VERSION_PATCH 0
+/** @} */
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -337,7 +358,9 @@ typedef enum {
 DLLEXPORT extern const int8_t utf8proc_utf8class[256];
 
 /**
- * Returns the version as a string.
+ * Returns the utf8proc API version as a string MAJOR.MINOR.PATCH
+ * (http://semver.org format), possibly with a "-dev" suffix for
+ * development versions.
  */
 DLLEXPORT const char *utf8proc_version(void);